package navigate

import (
	"common"
	"common/grpcx"
	"common/json_response"
	"gateway/internal/pb"
	"github.com/gin-gonic/gin"
	"time"
)

func GetList(ctx *gin.Context) {
	response := json_response.NewJsonHttpResponse(ctx)
	conn, err := grpcx.NewNoCertConn("comic")
	if err != nil {
		response.SetCode(json_response.CODE_ERROR).SetMsg("系统内部错误").Send()
		return
	}
	defer conn.Close()
	object := pb.NewComicClient(conn)
	objectCtx, cancel := common.WithTimeoutContext(time.Second * 2)
	defer cancel()

	res, err := object.GetNavigateList(objectCtx, &pb.GetNavigateListRequest{})
	if err != nil {
		response.SetCode(json_response.CODE_ERROR).SetMsg(err.Error()).Send()
		return
	}
	response.SetCode(json_response.CODE_SUCCESS).SetData(res.NavigateL).Send()
	return
}
